{extend name="common/block" /}
{block name="style"}
<style>

</style>
{/block}
{block name="content"}

<div class="layui-tab layui-tab-card" lay-filter="ltab">
    <ul class="layui-tab-title ">
        {volist name="group" id="vo"}
        <li {if $flag== $vo.tag}class="layui-this" {/if} lay-tag='{$vo.tag}' lay-id={$key} lay-flag="{$vo.tag}">{$vo.name}</li>
        {/volist}
    </ul>
    <div class="layui-tab-content">
        <form class="layui-form" style="margin-top:12px;" id="form">
           {php}echo $html;{/php}

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn"  lay-submit lay-filter="*">提交</button>
                </div>
            </div>

        </form>
    </div>
</div>


{/block}

{block name="script"}
<script>
    var loading;
    window.onload = function(){
        // layui.layer.close(loading);
    }
    layui.use(['layer', 'jquery', 'form','upload','element'], function () {
        var  layer = layui.layer
            , form = layui.form
            , element = layui.element
            , $ = layui.jquery;


        form.render();

        form.on('submit(*)',function(){
            var fd = new FormData(document.getElementById("form"));

            $.ajax({
                url:'{:url("/admin/System/create",["group"=>input("get.group","base")])}',
                type:'post',
                processData: false,//必须
                contentType: false,//必须
                data:fd,
                beforeSend:function(XHR){
                    var loading = layer.load();
                },
                complete:function(XHR,statusCode){
                    layer.close(loading);
                },
                success:function(r){
                    if (r.code == 1) {
                        layer.msg(r.msg);
                        setTimeout(function(){
                            location.reload()
                        },1500);
                    } else {
                        layer.msg(r.msg);
                    }
                },
                error:function(r){
                    layer.msg(r.msg);
                }
            })
            return false;
        })

        element.on('tab(ltab)',function (obj){
            loading = layer.msg('loading',{
                icon:16,
                shade:0.5
            });
            location.href='{:url("index")}?group='+$(this).attr('lay-flag');
        })

    })

 /*  function upload(event,e){
       var file = event.target.files[0]
        , preview = document.querySelector('.j-img-preview')
        , reader = new FileReader();
       $(e).next().val($(e).val())

       reader.addEventListener("load", function () {
           var image = new Image();
           image.title = file.name;
           image.src = this.result;
           image.classList.add('j-img-preview-item');
           preview.append( image );
       }, false);

       reader.readAsDataURL(file);

    }*/

</script>
{/block}
